/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
/* URL and tool bars */

#urlbar-container {
  padding-block: 0 !important;
}

:root[zen-single-toolbar='true'] {
  & #urlbar:not([breakout-extend='true']) {
    padding: 1px;
    --toolbarbutton-border-radius: 6px;
  }
}

#urlbar {
  --urlbarView-separator-color: light-dark(hsl(0, 0%, 74.9%), hsl(0, 0%, 20%));
  --urlbarView-hover-background: var(--toolbarbutton-hover-background);
  --urlbarView-highlight-background: var(--toolbarbutton-hover-background);
  border-radius: calc(var(--toolbarbutton-border-radius) - 2px);
  --urlbarView-results-padding: 10px !important;

  --urlbar-margin-inline: 5px;
  --urlbar-container-padding: 5px;
  :root[zen-single-toolbar='true'] & {
    --urlbar-container-padding: 4px;
  }
}

:root:not([zen-single-toolbar='true']) #urlbar:not([zen-floating-urlbar='true']) {
  --urlbarView-results-padding: 6px !important;
}

.urlbar-input::placeholder {
  text-overflow: ellipsis;
}

#searchbar:focus-within {
  border-color: transparent !important;
}

#urlbar-background {
  background: var(--zen-toolbar-element-bg) !important;
  border-radius: var(--border-radius-medium);
  outline: none !important;

  border: none !important;
  margin: 1px;

  box-shadow: none !important;
}

#urlbar[focused='true']:not([suppress-focus-border]) > #urlbar-background,
#searchbar:focus-within {
  outline: none !important;
  outline-offset: none !important;
  outline-color: none !important;
}

#urlbar:not([breakout-extend='true']) {
  :root:not([supress-primary-adjustment]) & #urlbar-background {
    transition: background-color 0.15s ease;
  }

  &:hover #urlbar-background {
    background-color: light-dark(rgba(0, 0, 0, 0.1), rgba(255, 255, 255, 0.2)) !important;
  }
}

#identity-box.chromeUI:not([pageproxystate='invalid']) {
  & #identity-icon-box {
    background: light-dark(rgba(0, 0, 0, 0.1), rgba(255, 255, 255, 0.1)) !important;
  }

  & #identity-icon-label {
    display: none;
  }
}

#identity-permission-box:not(:hover):not(:focus-within) {
  background: transparent !important;
}

#searchbar:focus-within {
  background: var(--urlbar-box-bgcolor);
}

#identity-box:not(.chromeUI) #identity-icon-label {
  padding-inline-start: 8px !important;
}

#urlbar:not([extend='true']) #identity-box #identity-icon-box {
  position: relative;
}

#identity-icon-box {
  outline: none !important;
}

#urlbar .urlbar-input {
  border-radius: 0 !important;
}

:root[zen-single-toolbar='true'] #urlbar:not([breakout-extend='true']) {
  & #urlbar-input {
    cursor: default;
  }

  & #identity-box {
    margin-inline-end: 0 !important;
    &.chromeUI:not([pageproxystate='invalid']) #identity-icon-box {
      border-radius: 10px !important;
    }
  }
}

.urlbar-page-action,
#tracking-protection-icon-container {
  padding: 0 !important;
  justify-content: center !important;
  align-items: center !important;
  margin: 0;

  :root[zen-single-toolbar='true'] & {
    padding: 6px !important;
    width: unset !important;
    height: unset !important;
  }
}

#tracking-protection-icon-container {
  margin: 0 0 0 2px !important;
}

.urlbar-page-action,
#tracking-protection-icon-container {
  margin-top: auto !important;
  margin-bottom: auto !important;
}

#tracking-protection-icon-container,
#page-action-buttons {
  order: 2 !important;
}

#urlbar[breakout] {
  position: fixed;
}

#urlbar[breakout-extend='true'] {
  z-index: 2;

  :root:not([zen-single-toolbar='true']) & .urlbar-input-container {
    --urlbar-container-padding: 0px;
  }

  & #identity-box {
    margin-right: calc(var(--urlbar-margin-inline) - 1px);
  }

  & #urlbar-background {
    --zen-urlbar-background-base: color-mix(
      in srgb,
      light-dark(hsl(0, 0%, 100%), hsl(0, 0%, 5%)) 80%,
      var(--zen-colors-primary) 20%
    );
    @media -moz-pref('zen.theme.acrylic-elements') {
      --zen-urlbar-background-transparent: color-mix(
        in srgb,
        var(--zen-urlbar-background-base) 70%,
        transparent 30%
      );
    }
    background-color: var(
      --zen-urlbar-background-transparent,
      var(--zen-urlbar-background-base)
    ) !important;
    box-shadow: 0px 0px 90px -10px rgba(0, 0, 0, 0.6) !important;
    backdrop-filter: none !important;
    border-radius: 12px !important;
    outline: 0.5px solid light-dark(rgba(0, 0, 0, 0.15), rgba(255, 255, 255, 0.15)) !important;
    outline-offset: -2px;
    @media -moz-pref('zen.theme.acrylic-elements') {
      backdrop-filter: blur(42px) saturate(110%) brightness(0.25) contrast(100%) !important;
    }
  }
}

#urlbar-go-button {
  display: none;
}

:root[zen-single-toolbar='true'] {
  --urlbar-icon-border-radius: 10px !important;

  .urlbar-page-action:not([open]):not(#identity-permission-box),
  #tracking-protection-icon-container {
    display: none;
  }

  #identity-box:not([pageproxystate='invalid']) #identity-icon-box:not([open]) {
    margin-inline-start: calc(-8px - 2 * var(--urlbar-icon-padding));
    transform: translateX(100%);
    opacity: 0;

    :root:not([supress-primary-adjustment]) & {
      transition: all 0.1s ease;
    }
  }

  #identity-permission-box > *:not(#permissions-granted-icon) {
    visibility: collapse;
  }

  #identity-icon-label {
    display: none;
  }

  #urlbar[open]
    :is(#tracking-protection-icon-container, .urlbar-page-action, .identity-box-button):not(
      [hidden='true']
    ):not(#identity-permission-box),
  #urlbar:hover #identity-icon-box {
    opacity: 1 !important;
    margin-inline-start: 0 !important;
    transform: none !important;
    display: flex;
    #urlbar:not(:hover) & {
      transition: none;
    }
  }

  #urlbar:not([open]) #userContext-icons {
    margin-inline: 0;
  }

  #urlbar:not([open]) {
    #identity-box:not([pageproxystate='invalid']) {
      order: 2;
    }
  }

  #notification-popup-box:not([open]) {
    margin-inline-start: calc(-10px - 2 * var(--urlbar-icon-padding));
    opacity: 0;
    transition: all 0.2s;
  }

  #notification-popup-box {
    align-items: center;
    justify-content: center;
    height: unset !important;
    background: transparent !important;

    & > image {
      margin-top: auto;
      margin-bottom: auto;
      height: 24px; /* double 12px */
      width: 24px;
      padding: 4px !important;

      &:hover {
        background: var(--toolbarbutton-hover-background);
        border-radius: var(--toolbarbutton-border-radius);
        overflow: visible;
      }
    }
  }
}

:root:not([zen-single-toolbar='true']) {
  #notification-popup-box {
    margin: 0 4px 0 0 !important;
    justify-content: center;
    gap: 8px;
    background: transparent;

    & > image {
      margin-top: auto;
      margin-bottom: auto;
      padding: 0;
    }
  }
}

#urlbar[breakout-extend='true'] #notification-popup-box {
  min-width: calc(var(--urlbar-min-height) - 4 * var(--urlbar-container-padding)) !important;
  height: calc(var(--urlbar-min-height) - 4 * var(--urlbar-container-padding)) !important;
}

button.popup-notification-dropmarker {
  border-top-left-radius: 0 !important;
  border-bottom-left-radius: 0 !important;
}

.panel-footer:has(button.popup-notification-dropmarker:not([hidden='true']))
  button.popup-notification-secondary-button {
  border-top-right-radius: 0 !important;
  border-bottom-right-radius: 0 !important;
}

.searchbar-engine-one-off-item {
  max-width: 28px;
  min-width: 28px !important;
  transition: background 0s;
  justify-content: center;
}

#downloadsHistory {
  margin-top: 5px;
}

#urlbar-container {
  container: urlbar-container / inline-size;
  z-index: 1;
}

@container urlbar-container (width < 350px) {
  #userContext-icons {
    transition: all 0.1s ease;
  }

  #userContext-label {
    display: none;
  }

  #userContext-indicator {
    margin-inline-end: 4px;
  }

  #urlbar:hover:not([breakout-extend='true']) #userContext-icons {
    margin-inline-end: calc(-16px - 2 * var(--urlbar-icon-padding)) !important;
    opacity: 0;
    pointer-events: none;
  }
}

@media (max-width: 550px) {
  #urlbar-container {
    width: calc(176px + 2 * (24px + 2 * var(--toolbarbutton-inner-padding)));
  }

  #nav-bar[downloadsbuttonshown] #urlbar-container,
  #nav-bar[unifiedextensionsbuttonshown] #urlbar-container {
    width: calc(76px + 24px + 2 * var(--toolbarbutton-inner-padding));
  }

  #nav-bar[downloadsbuttonshown][unifiedextensionsbuttonshown] #urlbar-container {
    width: 176px;
  }

  #identity-icon-box {
    max-width: 70px;
  }

  #urlbar-zoom-button {
    display: none;
  }
}

/* Thanks to https://github.com/JLBlk!
 * Checkout https://github.com/JLBlk/Zen-Themes/blob/main/SuperUrlBar/SuperUrlBar.css
 */

#notification-popup-box {
  border-radius: 10px !important;
}

/* Border radius on hover */
#urlbar .urlbar-page-action,
#urlbar #tracking-protection-icon-container,
#urlbar:not([breakout-extend='true'])
  #identity-box:is(:not(.chromeUI), [pageproxystate='invalid'])
  #identity-icon-box {
  border-radius: var(--urlbar-icon-border-radius) !important;
  min-width: 30px;
}

/* Notification Stack */

.notificationbox-stack {
  background: transparent;

  &[notificationside='top'] {
    position: fixed;
    bottom: calc(var(--zen-element-separation) * 1.5);
    right: calc(var(--zen-element-separation) * 1.5);
    width: fit-content;
    max-width: 30rem !important;

    & notification-message {
      background: color-mix(in srgb, var(--zen-colors-tertiary) 70%, transparent 30%);
      backdrop-filter: blur(10px);
      border: 1px solid var(--arrowpanel-border-color);
      border-radius: var(--zen-border-radius);

      &::before {
        display: none;
      }
    }
  }
}

#nav-bar,
#zen-sidebar-top-buttons {
  min-height: var(--zen-toolbar-height) !important;
  height: var(--zen-toolbar-height) !important;
  max-height: var(--zen-toolbar-height) !important;
  display: flex;
  align-items: center;
}

:root:not([zen-single-toolbar='true']) {
  &[zen-right-side='true']:not([zen-window-buttons-reversed='true']) #nav-bar {
    margin-inline-start: var(--zen-element-separation);
  }

  &:not([zen-right-side='true'])[zen-window-buttons-reversed='true'] #nav-bar {
    margin-inline-end: var(--zen-element-separation);
  }
}

/* Other small tweaks */
#nav-bar-customization-target {
  /* Don't grow if potentially-user-sized elements (like the searchbar or the
   * bookmarks toolbar item list) are too wide. This forces them to flex to the
   * available space as much as possible, see bug 1795260. */
  min-width: 0;

  --toolbarbutton-inner-padding: var(--zen-toolbar-button-inner-padding);

  /* Add space to beginning of toolbar and make that space click the first <toolbarbutton> */
  > :is(toolbarbutton, toolbaritem):first-child,
  > toolbarpaletteitem:first-child > :is(toolbarbutton, toolbaritem) {
    padding-inline-start: 0;
  }
}

/* TODO: Fix this for windows and macos */
/*.titlebar-button:last-child {
  padding-right: var(--zen-element-separation) !important;
}*/

#urlbar {
  & .search-panel-one-offs-header {
    display: none;
  }

  & .search-panel-one-offs-container .searchbar-engine-one-off-item {
    box-shadow: none;
  }
}

:root[zen-single-toolbar='true'] {
  #urlbar[open] {
    min-width: min(90%, 40rem);
  }

  &[zen-right-side='true'] #urlbar[open]:not([zen-floating-urlbar='true']) {
    right: 0;
  }
}

#urlbar[open][zen-floating-urlbar='true'] {
  z-index: 1000;
  max-width: unset;
  --urlbar-container-height: 55px !important;
  --urlbar-margin-inline: 10px !important;

  min-width: min(90%, 50rem) !important;
  width: var(--zen-urlbar-width, min(90%, 50rem)) !important;
  font-size: 1.15em !important;
  @media (-moz-platform: macos) {
    font-size: 1.5em !important;
    width: min(90%, 60rem) !important;
  }
  top: var(--zen-urlbar-top) !important;
  transform: translateX(-50%);
  left: 50% !important;

  #urlbar-container:has(&) {
    border-radius: var(--border-radius-medium);
    background: var(--toolbarbutton-hover-background);
    height: var(--urlbar-height) !important;
    margin-inline: 0.15rem !important;
    :root:not([zen-single-toolbar='true']) & {
      max-height: 32px !important;
      min-height: unset !important;
      margin-block: -1px !important;
    }
  }
}

@media not -moz-pref('zen.urlbar.show-protections-icon') {
  #tracking-protection-icon-container {
    display: none !important;
  }
}

#urlbar-search-mode-indicator {
  background-color: color-mix(in srgb, var(--zen-primary-color) 50%, transparent 50%) !important;
}

/* Code ~~stolen~~ taken inspiration from https://github.com/greeeen-dev/zen-arc-cmd-bar
 *
 * MIT License
 *
 * Copyright (c) 2024 green.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 **/
.urlbarView-title,
.urlbarView-title-separator,
.urlbarView-action,
.urlbarView-url {
  margin-top: auto !important;
  margin-bottom: auto !important;
}

.urlbarView-title {
  font-size: 14px !important;
  font-weight: 500 !important;
}

.urlbarView-url,
.urlbarView-title-separator::before {
  font-size: 14px !important;
  font-weight: 500 !important;
  color: #aaa !important;
}

.urlbarView-favicon {
  margin-left: 0 !important;
  margin-right: 12px !important;
  padding: 6px !important;
  border-radius: 4px !important;
}

.urlbarView-userContext {
  border-top: none !important;
}

.urlbarView-row[has-action]:is([type='switchtab'], [type='remotetab'], [type='clipboard']) {
  & .urlbarView-action {
    margin-left: auto !important;
    margin-right: 0 !important;
  }

  &:is([type='switchtab'], [type='remotetab']) .urlbarView-action {
    background: transparent !important;
    align-items: center;
    display: flex;
    gap: 12px;
    font-weight: 600;
    margin-right: 28px !important;
    position: relative;
    scale: 0.93;
    transform-origin: right;

    &::after {
      content: '';
      display: inline-block;
      width: 28px;
      height: 28px;

      background-color: currentColor;
      mask-image: url('chrome://browser/skin/zen-icons/urlbar-arrow.svg');
      mask-size: contain;
      mask-repeat: no-repeat;
      mask-position: center;
      pointer-events: none;
      position: absolute;

      right: -28px;
    }
  }

  & .urlbarView-no-wrap {
    width: 100%;
  }
}

.urlbarView-no-wrap {
  align-items: center !important;
}

.urlbarView-row {
  color: light-dark(rgba(0, 0, 0, 0.7), rgba(255, 255, 255, 0.7)) !important;
}

#urlbar-label-box {
  background-color: color-mix(in srgb, var(--zen-primary-color) 50%, transparent 50%) !important;
  border-radius: 6px !important;
}

.urlbarView-row {
  --urlbarView-item-inline-padding: 8px;
  --urlbarView-item-block-padding: 10px;

  &:hover {
    .urlbarView-favicon,
    & {
      background-color: color-mix(
        in srgb,
        var(--zen-branding-bg-reverse) 5%,
        transparent 95%
      ) !important;
    }
  }

  &[selected] {
    background-color: color-mix(in srgb, var(--zen-primary-color) 50%, transparent 50%) !important;

    & *,
    & .urlbarView-title-separator::before {
      color: light-dark(black, white) !important;
    }

    & .urlbarView-favicon {
      fill: black !important;
    }

    & .urlbarView-favicon {
      background-color: rgba(255, 255, 255, 0.9) !important;
    }
  }
}
